#ifndef CONCREATEAGGREGATE_H
#define CONCREATEAGGREGATE_H

#include "Iterator.h"
#include "ConcreateIterater.h"
#include "Aggregate.h"

template<class T>
class ConcreateAggregate : public Aggregate<T>
{
public:
	ConcreateAggregate(int nSize);
	virtual ~ConcreateAggregate();

	Iterator<T>* crateIterator();

	int getSize();

	T getItem(int nIndex);

private:
	T* data;
	int nSize;
};

template<class T>
ConcreateAggregate<T>::ConcreateAggregate(int number)
{
	this->nSize = number;

	this->data = new T[number];


	for (int i = 0; i < number; i++) {
		this->data[i] = i;
	}
}

template<class T>
Iterator<T>* ConcreateAggregate<T>::crateIterator()
{
	return new ConcreateIterater<T>(this);
}

template<class T>
int ConcreateAggregate<T>::getSize()
{
	return this->nSize;
}

template<class T>
T ConcreateAggregate<T>::getItem(int nIndex)
{
	if (nIndex < 0 || nIndex > this->nSize) {
		return static_cast<T>(-1);
	}

	return this->data[nIndex];

}

template<class T>
ConcreateAggregate<T>::~ConcreateAggregate()
{
	for (int i = 0; i < this->nSize; i++) {
		delete& this->data[i];
	}

	this->data = nullptr;

	this->nSize = 0;
}

#endif // CONCREATEAGGREGATE_H
